package zzzxb.ui;

import com.sun.javaws.exceptions.JRESelectException;
import zzzxb.generation.ConditionalRules;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author Zzzxb  2019/8/10 23:36
 * @description:
 */
public class FileInfo extends JFrame {
    private FileInfoJpanel fileInfoJpanel;

    public FileInfo() throws HeadlessException {
        fileInfoJpanel = new FileInfoJpanel();
        this.setTitle("生成文件信息");
        this.setSize(300,300);
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setVisible(true);
        this.setContentPane(fileInfoJpanel);
    }
}

class FileInfoJpanel extends JPanel {
    private JLabel nameLabel;
    private JLabel tagLabel;
    private JTextField nameField;
    private JTextField tagField;
    private JButton submit;

    public FileInfoJpanel() {
        this.setLayout(null);
        nameLabel = new JLabel("Name:");
        tagLabel = new JLabel("Tag:");
        nameField = new JTextField();
        tagField = new JTextField();
        submit = new JButton("submit");
        init();
        listen();
    }

    public void init() {
        nameLabel.setBounds(30,20,50,30);
        nameField.setBounds(70, 20, 180,30);
        tagLabel.setBounds(30,60,50,30);
        tagField.setBounds(70,60,180,30);
        submit.setBounds(100,200,100,30);

        this.add(nameLabel);
        this.add(nameField);
        this.add(tagLabel);
        this.add(tagField);
        this.add(submit);
    }

    public void listen() {
        submit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ConditionalRules.format.setFileName(nameField.getText());
                ConditionalRules.format.setTag(tagField.getText());
            }
        });
    }
}
